package com.annchain.og_browser.service;

import com.annchain.og_browser.entity.OgbKnownAddress;
import com.annchain.og_browser.mapper.OgbAddressMapper;
import com.annchain.og_browser.mapper.OgbKnowAddressMapper;
import com.annchain.og_browser.vo.AddressVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KnownAddressService {

    @Autowired
    private OgbKnowAddressMapper ogbKnowAddressMapper;

    public AddressVo getAddress(String address) {
        if (address == null) {
            return null;
        }
        AddressVo av = new AddressVo();
        av.setAddress(address);
        av.setKnown(false);

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("address", address);
        OgbKnownAddress ogbKnownAddress = ogbKnowAddressMapper.selectOne(wrapper);
        if (ogbKnownAddress != null) {
            av.setKnown(true);
            av.setName(ogbKnownAddress.getName());
            av.setLogoUrl(ogbKnownAddress.getLogoUrl());
        }
        return av;
    }

}
